import request from '../utils/axios';
import { uploadURL } from '@/utils/axios.ts'; 


export function getFullPath(path){
	if ( !path ) return;
	path = path.replace(/\s/g, encodeURIComponent(' '));
	return uploadURL + '/file/upload/getFileByPath?filePath=' + path;
} 

export function getTplList(data) {
	return request({
		url: '/inspectionTargetTemplate/getTemplateList',
		method: 'get',
	    params:data
	});
}
export function getTplCode(data) {
	return request({
		url: '/inspectionTargetTemplate/getTemplateCode',
		method: 'get',
	    params:data
	});
}
// 获取巡检项导入模板
export function getExcelTpl(data) {
	return request({
		url: '/file/upload/template/getInspectionImportTemplate',
		method: 'get',
	    params:data
	});
}
export function patchImport(data) {
	let formData = new FormData();
	Object.keys(data).forEach(key=>{
		formData.append(key, data[key]);
	})
	return request({
		url: '/inspectionItem/batch/import',
		method: 'post',
		data:formData
	});
}
// 巡检模板标签列表
export function getLabelList(data) {
	return request({
		url: '/inspectionLabel/getInspectionLabelList',
		method: 'get',
	    params:data
	});
}
export function getMeterTypeList(data) {
	return request({
		url: '/inspectionTargetTemplate/getEquipmentTypeList',
		method: 'get',
	    params:data
	});
}
export function addOrUpdateTpl(data, forEdit) {
    if ( forEdit ) {
        return request({
            url: '/inspectionTargetTemplate/editTemplate',
            method: 'put',
            data
        });
    } else {
        return request({
            url: '/inspectionTargetTemplate/addTemplate',
            method: 'post',
            data
        });
    }
}

export function delTpl(data) {
	let formData = new FormData();
	Object.keys(data).forEach(key=>{
		formData.append(key, data[key]);
	})
	return request({
		url: '/inspectionTargetTemplate/delTemplateCode',
		method: 'delete',
		data:formData
	});
}

// 模板的巡检项接口
export function getTplInspectionList(data, forObj) {
	
	return request({
		url: forObj ? '/inspectionItemTarget/getInspectionItemList' : '/inspectionItem/getInspectionItemList',
		method: 'get',
	    params:data
	});
}

export function addOrUpdateInspection(data, forEdit, forObj) {
    if ( forEdit ) {
        return request({
            url: forObj ? '/inspectionItemTarget/editInspectionItem' : '/inspectionItem/editInspectionItem',
            method: 'put',
            data
        });
    } else {
        return request({
            url: forObj ? '/inspectionItemTarget/addInspectionItem' : '/inspectionItem/addInspectionItem',
            method: 'post',
            data
        });
    }
}

export function delInspection(data, forObj) {
	let formData = new FormData();
	Object.keys(data).forEach(key=>{
		formData.append(key, data[key]);
	})
	return request({
		url: forObj ? '/inspectionItemTarget/delInspectionItem' : '/inspectionItem/delInspectionItem',
		method: 'delete',
		data:formData
	});
}
